import LeaderLine from "leader-line-vue";
import CryptoJS from "crypto-js";
import {useSysStore} from "stores/sysMessage";


export const setLine = (s,e) => {
//引导线--开始节点
    let start = s;
    //引导线--结束节点
    let end = e;
    return LeaderLine.setLine(start, end, {
        // dash: true,//是否虚线
        dash: { animation: true }, //引导线虚线&动效
        color: "red", //引导线颜色
        positionByWindowResize: true,
        size: 2,
        gradient: {
            //配置引导线显色  如果为true则使用默认颜色
            startColor: "#2e17c3",
            endColor: "#1df3f9",
        },
        //引导线阴影
        dropShadow: { dx: 0, dy: 3 },
        startLabel: "",
        middleLabel: "",
        endLabel: "",
    })
}
export function generateUUID() {
    if (typeof crypto === 'object') {
        if (typeof crypto.randomUUID === 'function') {
            return crypto.randomUUID();
        }
        if (typeof crypto.getRandomValues === 'function' && typeof Uint8Array === 'function') {
            const callback = (c) => {
                const num = Number(c);
                return (num ^ (crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (num / 4)))).toString(16);
            };
            return '10000000-1000-4000-8000-100000000000'.replace(/[018]/g, callback);
        }
    }
    let timestamp = new Date().getTime();
    let performanceNow = (typeof performance !== 'undefined' && performance.now && performance.now() * 1000) || 0;
    return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
        let random = Math.random() * 16;
        if (timestamp > 0) {
            random = (timestamp + random) % 16 | 0;
            timestamp = Math.floor(timestamp / 16);
        } else {
            random = (performanceNow + random) % 16 | 0;
            performanceNow = Math.floor(performanceNow / 16);
        }
        return (c === 'x' ? random : (random & 0x3) | 0x8).toString(16);
    });
}
/**
 *获取真实的下载地址
 */
export function getRealDownloadUrl(url) {
    return new Promise(resolve => {
        const xhr = new XMLHttpRequest();

        xhr.open('GET', url, true);
        xhr.onload = () => {
            if (xhr.status === 200) {
                resolve(JSON.parse(xhr.response).data);
            }
        };
        xhr.send();
    });
}

/**
 *加密处理
 */
export function encryption(src, keyWord) {
    const key = CryptoJS.enc.Utf8.parse(keyWord);
    // 加密
    let encrypted = CryptoJS.AES.encrypt(src, key, {
        iv: key,
        mode: CryptoJS.mode.CFB,
        padding: CryptoJS.pad.NoPadding,
    });
    return encrypted.toString();
}

/**
 *判断帐号是否有操作权限
 */
let sysStore = useSysStore();
export function canEdit() {
   return sysStore.userInfo.name == 'isaac';
}
